#include "login.h"
#include "ui_login.h"

login::login(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::login)
{

    ui->setupUi(this);



}

login::~login()
{
    delete ui;
}

void login::on_loginButton_clicked()//登录
{

    QString account = ui->lineEdit_account->text();//获得账号
         QString password = ui->lineEdit_password->text();//获得密码
         if(account.isEmpty())
         {
             QMessageBox::information(this,"提示","账号不能为空");
         }
         else if(password.isEmpty())
         {
             QMessageBox::information(this,"提示","密码不能为空");
         }
         else
    {QSqlQuery query;
            query.prepare("SELECT 身份证号码 FROM 用户表 WHERE 账号 = :account AND 密码 = :password");
            query.bindValue(":account", account);
            query.bindValue(":password", password);
            query.exec();//在用户表查询账号密码
            if (query.next()) {
                Form::now_account_id=query.value(0).toString();
                Form::now_account=account;
                this->hide();
                userface*u=new userface;
                connect(u,SIGNAL(sendsignal()),this,SLOT(reshow()));//当点击子界面时，调用主界面的reshow()函数
                u->show();//打开用户功能界面
            } else {
                // 登录失败
                QMessageBox::information(this,"提示","账号或密码错误");

            }}
}

void login::on_signupButton_clicked()
{
this->hide();
    signup *s=new signup;
    connect(s,SIGNAL(sendsignal()),this,SLOT(reshow()));//当点击子界面时，调用主界面的reshow()函数
    s->show();
}
void login::reshow(){
    this->show();
}
